package com.ddwl.shop.service;

import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.schema.bo.shop.ShopUserRecordBo;
import com.ddwl.schema.vo.shop.ShopVo;
import com.ddwl.shop.dao.ShopDao;
import com.ddwl.shop.dao.ShopUserRecordDao;
import com.ddwl.shop.dao.model.Shop;
import com.ddwl.shop.dao.model.ShopUserRecord;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.util.StringUtil;

import javax.annotation.Resource;

/**
 * 门店登录记录
 * @author wenbin
 */
@Service
public class ShopUserRecordService {

    @Resource
    private ShopUserRecordDao shopUserRecordDao;
    @Resource
    private ShopDao shopDao;

    public void saveShopUserRecord(ShopUserRecordBo bo) {
        if (StringUtil.isEmpty(bo.getShopId())){
            Shop shop=new Shop();
            shop.setDefaultTag(1);
            ShopVo shopVo = BeanConverUtils.convertBean(shopDao.selectOne(shop),ShopVo.class);
            if(shopVo==null){
                return;
            }
            bo.setShopId(shopVo.getId());
        }
        ShopUserRecord shopUserRecord = BeanConverUtils.convertBean(bo, ShopUserRecord.class);
        shopUserRecordDao.insert(shopUserRecord);
    }

    /**
     * 查询用户最近浏览店铺
     */
    public String queryRelateRecord(String userId) {
        return shopUserRecordDao.queryRelateRecord(userId);
    }
}
